package com.example.baselib.utils;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.Component;
import ohos.agp.window.service.DisplayAttributes;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;

public class UIUtils {


    public static <T extends Component> T findComponentFromId(Component component, int id) {
        return (T) component.findComponentById(id);
    }

    public static <T extends Component> T findComponentFromId(AbilitySlice abilitySlice, int id) {
        return (T) abilitySlice.findComponentById(id);
    }

    public static <T extends Component> T findComponentFromId(Ability ability, int id) {
        return (T) ability.findComponentById(id);
    }

    public static int vp2px(Context context, float vp) {
        DisplayAttributes attributes = DisplayManager.getInstance().getDefaultDisplay(context).get().getAttributes();
        return (int) (attributes.densityPixels * vp);
    }


}
